Skip to content

Refactor cmake-rn to use a platform abstraction #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 22, 2025

Conversation

kraenhansen
Copy link
Collaborator

As a preparation for #175 I propose introducing the a "platform" interface, implementable to add support for a subset of targets.

@kraenhansen kraenhansen self-assigned this Jul 20, 2025
@kraenhansen kraenhansen added Apple 🍎 Anything related to the Apple platform (iOS, macOS, Cocoapods, Xcode, XCFrameworks, etc.) Android 🤖 Anything related to the Android platform (Gradle, NDK, Android SDK) CMake RN Our `cmake` wrapping CLI labels Jul 20, 2025
Copy link

changeset-bot bot commented Jul 20, 2025

🦋 Changeset detected

Latest commit: 2ca36b5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
cmake-rn Patch
react-native-node-api Patch
ferric-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kraenhansen kraenhansen changed the title Refactor into a cmake-rn platform abstraction Refactor cmake-rn to use a platform abstraction Jul 20, 2025
@kraenhansen kraenhansen force-pushed the kh/cmake-rn-platforms branch from 2459faf to 0f7be36 Compare July 22, 2025 18:30
@kraenhansen kraenhansen requested a review from Copilot July 22, 2025 19:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the cmake-rn package to use a platform abstraction layer, introducing interfaces for supporting different build targets in a more structured way. This prepares the codebase for future platform additions and improves separation of concerns.

  • Introduces a Platform interface with platform-specific implementations for Android and Apple targets
  • Refactors CLI to use the new platform abstraction instead of direct triplet handling
  • Consolidates weak-node-api path handling through a centralized module

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/host/src/node/weak-node-api.ts New module providing centralized weak-node-api path resolution
packages/host/src/node/prebuilds/triplets.ts Adds type guard function and improves existing triplet type guards
packages/host/src/node/path-utils.ts Improves error message and adds input validation
packages/host/src/node/index.ts Updates exports to include new utilities
packages/host/package.json Updates weak-node-api export path
packages/ferric/src/cargo.ts Refactors to use centralized weak-node-api path
packages/cmake-rn/tsconfig*.json Restructures TypeScript configuration with separate configs
packages/cmake-rn/src/weak-node-api.ts Updates to use centralized weak-node-api path
packages/cmake-rn/src/platforms/types.ts Defines platform abstraction interface
packages/cmake-rn/src/platforms/apple.ts Apple platform implementation
packages/cmake-rn/src/platforms/android.ts Android platform implementation
packages/cmake-rn/src/platforms.ts Platform registry and utilities
packages/cmake-rn/src/platforms.test.ts Tests for platform utilities
packages/cmake-rn/src/cli.ts Major refactor to use platform abstraction
packages/cmake-rn/src/apple.ts Removed (functionality moved to platforms/apple.ts)
packages/cmake-rn/src/android.ts Removed (functionality moved to platforms/android.ts)

Comment on lines +2 to +8
import type { program } from "../cli.js";

type InferOptionValues<Command extends commander.Command> = ReturnType<
Command["opts"]
>;

type BaseCommand = typeof program;
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type BaseCommand references program which is imported from a sibling module. This creates a circular dependency risk since the CLI module also imports from this types module. Consider defining the command type interface directly here instead of importing it.

Suggested change
import type { program } from "../cli.js";
type InferOptionValues<Command extends commander.Command> = ReturnType<
Command["opts"]
>;
type BaseCommand = typeof program;
type InferOptionValues<Command extends commander.Command> = ReturnType<
Command["opts"]
>;
type BaseCommand = commander.Command<
[],
Record<string, unknown>,
Record<string, unknown>
>;

Copilot uses AI. Check for mistakes.

Comment on lines +166 to +167
assert.equal(result.length, 1, "Expected exactly one library file");
return await result[0];
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion checks result.length but result is an array of promises, not resolved file paths. The check should be performed after awaiting the promises. Move this assertion after return await result[0]; or await all promises first.

Suggested change
assert.equal(result.length, 1, "Expected exactly one library file");
return await result[0];
const resolvedResults = await Promise.all(resultPromises);
assert.equal(resolvedResults.length, 1, "Expected exactly one library file");
return resolvedResults[0];

Copilot uses AI. Check for mistakes.

const architecture = ANDROID_ARCHITECTURES[target];

return [
// Use the XCode as generator for Apple platforms
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment mentions 'XCode' and 'Apple platforms' but this is in the Android platform implementation. The comment should be corrected to reference Android/Ninja instead.

Suggested change
// Use the XCode as generator for Apple platforms
// Use the Ninja generator for Android platforms

Copilot uses AI. Check for mistakes.

Comment on lines 146 to 147
options: baseOptions as BaseOpts &
ReturnType<typeof platform.buildArgs>,
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type assertion baseOptions as BaseOpts & ReturnType<typeof platform.buildArgs> is unsafe because platform.buildArgs returns a string array, not an options object. This suggests a type modeling issue in the platform abstraction.

Suggested change
options: baseOptions as BaseOpts &
ReturnType<typeof platform.buildArgs>,
options: {
...baseOptions,
...platform.buildArgs(),
} as BaseOpts,

Copilot uses AI. Check for mistakes.

@kraenhansen kraenhansen merged commit 4924f66 into main Jul 22, 2025
6 checks passed
@kraenhansen kraenhansen deleted the kh/cmake-rn-platforms branch July 22, 2025 19:58
kraenhansen added a commit that referenced this pull request Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android 🤖 Anything related to the Android platform (Gradle, NDK, Android SDK) Apple 🍎 Anything related to the Apple platform (iOS, macOS, Cocoapods, Xcode, XCFrameworks, etc.) CMake RN Our `cmake` wrapping CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant